<?php
/**
 * Customar Order components
 * 
 * No redirection nor database manipulation ( insert, update, delete ) here
 */
class customarOrderComponents extends myFrontModuleComponents
{

  public function executeList()
  {
    $query = $this->getListQuery();
    
    $this->customarOrderPager = $this->getPager($query);
  }

  public function executeShow()
  {
    $query = $this->getShowQuery();
    
    $this->customarOrder = $this->getRecord($query);
  }

  public function executeAddToCart(dmWebRequest $request)
  {
        $this->getUser()->getCartCookieSession();
        $shopping_cart = $this->getUser()->getShoppingCart();
        $this->shopping_cart = $shopping_cart;
        $this->items = $shopping_cart->getItems();

  }

  public function executeShippingMethod(dmWebRequest $request)
  {
    // Your code here
        $this->updateFlag = false;
        $this->selectedMethodId = false;
        $shopping_cart = $this->getUser()->getShoppingCart();
        $this->shopping_cart = $shopping_cart;
        $this->form = $this->forms['ProfileShipping'];
  }

  public function executePayment(dmWebRequest $request)
  {
    // Your code here
        $this->selectedMethodId = false;
        $this->plaseOreder = false;
        if($request->isMethod('post'))
        {
            if($request->hasParameter('shipping_method'))
                $this->getUser()->setAttribute('shipping_method', $request->getPostParameter('shipping_method'));
            if($request->hasParameter('update_payment') && $request->getParameter('update_payment'))
            {
                    $this->plaseOreder = true;
                    $this->getUser()->setAttribute('payment_method', $request->getPostParameter('payment_method_id'));
                    $this->selectedPaymentMethod = PaymentMethodTable::getInstance()->find($request->getPostParameter('payment_method_id'));
                    $this->selectedMethodId = true;
            }
        }
        $query = PaymentMethodTable::getInstance()->createQuery()->where('is_active',true);
        $this->paymentmethods = $this->getPager($query);
        $shopping_cart = $this->getUser()->getShoppingCart();
        $this->shopping_cart = $shopping_cart;
        $this->shippingMethod = ShippingMethodTable::getInstance()->find($this->getUser()->getAttribute('shipping_method'));
  }

  public function executePaymentSuccess(dmWebRequest $request)
  {
    // Your code here
      $this->userPaymentInfo =  $this->getUser()->getAttribute('added_order');
      $this->getUser()->setAttribute('added_order','');
  }


}
